%% Create an instance of the XFOIl class
xf = XFOIL();
xf.KeepFiles = true;  % To keep all intermediate files created
xf.Visible = true,    % To show XFOIL plotting window

%% Create an airfoil
xf.Airfoil = Airfoil('2032c.dat'); % To load an exisitng airfoil 
% To create a NACA 4-series>> xf.Airfoil = Airfoil.createNACA4('0012');

%% Setup the action list

% Add five filtering steps to smooth the airfoil coordinates and help
% convergence 
xf.addFiltering(5);

% Switch to OPER mode, and set Reynolds No. & Mach No.
xf.addOperation(3E7,0.1);

% Set maximum iteration times
sf.addIter(1000)

% Initialize the calculation
xf.addAlpha(0,true)

% Create a new polar
xf.addPolarFile('2032c.txt');

%% Calculate a sequence of AOA
xf.addAlpha(-10:0.5:20)

% Close the polar file
xf.addCLosePolarFile

% Quit XFOIl
xf.addQuit

%% Run the XFOIL
xf.run
disp('Running XFOIL...')

%% Wait up to 100 seconds for it to finish... 
%It is possible to run more than one XFOIL instance at the same time
finished = xf.wait(100); 

%% If successful, read and plot the polar
if finished
    disp('XFOIL analysis fininshed')
    xf.readPolars;
    figure
    xf.plotPolar(1);
else
    xf.kill;
end
